<template>
    <!-- 对话框表单 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :model-value="['Add', 'Edit'].includes(baTable.form.operate!)"
        @close="baTable.toggleForm"
        :destroy-on-close="true"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                {{ baTable.form.operate ? t(baTable.form.operate) : '' }}
            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
            <div
                class="ba-operate-form"
                :class="'ba-' + baTable.form.operate + '-form'"
                :style="config.layout.shrink ? '' : 'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
            >
                <el-form
                    ref="formRef"
                    @keyup.enter="baTable.onSubmit(formRef)"
                    :model="baTable.form.items"
                    :label-position="config.layout.shrink ? 'top' : 'right'"
                    :label-width="baTable.form.labelWidth + 'px'"
                    :rules="rules"
                    v-if="!baTable.form.loading"
                >
                    <FormItem
                        :label="t('order.orderWh.buyer_name')"
                        v-model="baTable.form.items!.name"
                        type="string"
                        prop="name"
                        :placeholder="t('Please input field', { field: t('order.orderWh.buyer_name') })"
                    />
                    <FormItem
                        :label="t('order.orderWh.link')"
                        v-model="baTable.form.items!.link"
                        type="string"
                        prop="link"
                        :placeholder="t('Please input field', { field: t('order.orderWh.link') })"
                    />
                    <FormItem
                        :label="t('order.orderWh.skuinfo')"
                        v-model="baTable.form.items!.skuinfo"
                        type="string"
                        prop="skuinfo"
                        :placeholder="t('Please input field', { field: t('order.orderWh.skuinfo') })"
                    />
                    <FormItem
                        :label="t('order.orderWh.buyer_email')"
                        v-model="baTable.form.items!.buyer_email"
                        type="string"
                        prop="buyer_email"
                        :placeholder="t('Please input field', { field: t('order.orderWh.buyer_email') })"
                    />
                    <FormItem
                        :label="t('order.orderWh.phone_number')"
                        v-model="baTable.form.items!.phone_number"
                        type="string"
                        prop="phone_number"
                        :placeholder="t('Please input field', { field: t('order.orderWh.phone_number') })"
                    />
                    <FormItem
                        :label="t('order.orderWh.address_detail')"
                        v-model="baTable.form.items!.address_detail"
                        type="string"
                        prop="address_detail"
                        :placeholder="t('Please input field', { field: t('order.orderWh.address_detail') })"
                    />
                    <FormItem
                        :label="t('order.orderWh.postal_code')"
                        v-model="baTable.form.items!.postal_code"
                        type="string"
                        prop="postal_code"
                        :placeholder="t('Please input field', { field: t('order.orderWh.postal_code') })"
                    />
                    <FormItem
                        :label="t('order.orderWh.state')"
                        v-model="baTable.form.items!.state"
                        type="string"
                        prop="state"
                        :placeholder="t('Please input field', { field: t('order.orderWh.state') })"
                    />
                    <FormItem
                        :label="t('order.orderWh.city')"
                        v-model="baTable.form.items!.city"
                        type="string"
                        prop="city"
                        :placeholder="t('Please input field', { field: t('order.orderWh.city') })"
                    />
                    <FormItem
                        :label="t('order.orderWh.county')"
                        v-model="baTable.form.items!.county"
                        type="string"
                        prop="county"
                        :placeholder="t('Please input field', { field: t('order.orderWh.county') })"
                    />
                    <FormItem
                        :label="t('order.orderWh.remarks')"
                        v-model="baTable.form.items!.remarks"
                        type="string"
                        prop="remarks"
                        :placeholder="t('Please input field', { field: t('order.orderWh.remarks') })"
                    />
                </el-form>
            </div>
        </el-scrollbar>
        <template #footer>
            <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
                <el-button @click="baTable.toggleForm('')">{{ t('Cancel') }}</el-button>
                <el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)" type="primary">
                    {{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('Save') }}
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { ref, reactive, inject, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import type baTableClass from '/@/utils/baTable'
import { buildValidatorData } from '/@/utils/validate'
import type { FormInstance } from 'element-plus'
import FormItem from '/@/components/formItem/index.vue'
import { useAdminInfo } from '/@/stores/adminInfo'
import { useConfig } from '/@/stores/config'

const config = useConfig()
const adminInfo = useAdminInfo()
const formRef = ref<FormInstance>()
const baTable = inject('baTable') as baTableClass

const { t } = useI18n()


watch(
    () => baTable.form.operate,
    (newVal) => {
        //rules.mobile![0].required = newVal == 'Add'
    }
)
</script>